home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2410 / 2410.xpi / chrome / content / foxmarks-login.js < prev    next >
Text File  |  2010-01-28  |  3KB  |  90 lines

  1. /*
  2.  Copyright 2008 Foxmarks Inc.
  3.  
  4.  foxmarks-login.js: Implements the client-side behavior for Account Manager.
  5.  
  6.  */
  7.  
  8.  
  9. var firstTime = true;
  10.  
  11. function FoxmarksLoginOnLoad() {
  12.     var iframe = document.getElementById("foxmarks-iframe");
  13.     if (firstTime) {
  14.         iframe.addEventListener("DOMContentLoaded", FoxmarksIFrameOnLoad, true);
  15.         firstTime = false;
  16.     } else {
  17.         iframe.setAttribute("src", "");
  18.     }
  19.  
  20.     var url = Xmarks.gSettings.wizardUrl;
  21.     var params = [];
  22.     if (Xmarks.gSettings.username) {
  23.         params.push("_username=" + Xmarks.gSettings.username);
  24.     }
  25.     params.push("_ua=" + Xmarks.FoxmarksVersion());
  26.     params.push("_app=jezebel");
  27.     params.push("_version=" + Xmarks.FoxmarksVersion()); 
  28.     params.push("_remempw=" + (Xmarks.gSettings.rememberPassword ? "on" : "off"));
  29.     params.push("_mid=" + Xmarks.gSettings.machineId);
  30.     params.push("_manual=" + window.arguments[0]);
  31.     Xmarks.gSettings.sessionID = Date.now().toString(36);
  32.     params.push("_sess=" + Xmarks.gSettings.sessionID);
  33.  
  34.  
  35.     if (params.length) {
  36.         url += ("?" + params.join("&"));
  37.     }
  38.  
  39.     iframe.setAttribute("src", url);
  40. }
  41.  
  42. function FoxmarksIFrameOnLoad(event) {
  43.     var pathname = event.originalTarget.location.pathname;
  44.     var query = event.originalTarget.location.search;
  45.     
  46.     // Extract values from DOM.
  47.     try {
  48.         var form = event.originalTarget.getElementById("user_account_form");
  49.         var formKids = [];
  50.         if(form){
  51.             formKids = form.childNodes;
  52.         }
  53.     } catch (e) {
  54.         var ps = Components.classes
  55.             ["@mozilla.org/embedcomp/prompt-service;1"]
  56.             .getService(Components.interfaces.nsIPromptService);
  57.         if (ps.confirm(null, "Xmarks",
  58.                     Xmarks.Bundle().GetStringFromName("msg.nosetupwizard"))) {
  59.             FoxmarksLoginOnLoad();  // restart it
  60.             return;
  61.         } else {
  62.             window.close();
  63.             return;
  64.         }
  65.     }
  66.  
  67.     var obj = {};
  68.     for (var i = 0; i < formKids.length; ++i) {
  69.         if (formKids[i].name) {
  70.             obj[formKids[i].name] = formKids[i].value;
  71.         }
  72.     }
  73.  
  74.     if (obj["_flag"] == 'cancel') {
  75.         if (Xmarks.OnWizardCancel()) {
  76.             window.close();
  77.         }
  78.     } else if (obj["_flag"] == 'done') {
  79.         Xmarks.gSettings.username = obj["_username"];
  80.         Xmarks.gSettings.password = obj["_password"];
  81.         Xmarks.gSettings.rememberPassword = (obj["_remempw"] == "on");
  82.         window.close();
  83.         var win = 
  84.             window.openDialog("chrome://foxmarks/content/foxmarks-setup.xul",
  85.                 "Xmarks", "chrome", window.arguments[0], "normal");
  86.             win.moveTo(window.screenX, window.screenY);
  87.     }
  88. }
  89.  
  90.